% Remember to use the lgrind style

\Head{}
\File{./java/FloorLinker.java}{2006}{4}{27}{19:09}{5835}
\L{\LB{\C{}/*}}
\L{\LB{_*_FloorLinker.java}}
\L{\LB{_*}}
\L{\LB{_*_Created_on_February_7,_2006,_2:11_PM}}
\L{\LB{_*/\CE{}}}
\L{\LB{}}
\L{\LB{\K{package}_\V{project01};}}
\L{\LB{}}
\L{\LB{\K{import}_\V{javax}.\V{swing}.*;}}
\L{\LB{\K{import}_\V{javax}.\V{swing}.\V{event}.*;}}
\L{\LB{\K{import}_\V{java}.\V{awt}.*;}}
\L{\LB{\K{import}_\V{java}.\V{awt}.\V{event}.*;}}
\L{\LB{\K{import}_\V{java}.\V{applet}.*;}}
\L{\LB{\K{import}_\V{java}.\V{util}.*;}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}/**}}
\L{\LB{_*_A_small_map_window_that_allows_the_user_to_select_a_floor-link_node.}}
\L{\LB{_*_Intended_to_be_launched_from_Editor_mode,_in_NodeEditor_in_the_Floors_tab,}}
\L{\LB{_*_when_user_selects_\3Add_New_Link\3._This_is_not_a_primary_mode_window,}}
\L{\LB{_*_and_therefore_is_not_intended_to_be_run_on_application_launch._Cannot_be}}
\L{\LB{_*_run_as_an_applet.}}
\L{\LB{_*_}}
\L{\LB{_*_\CE{}\V{author}_\V{Ian}_\V{Melnick}}}
\L{\LB{\C{}*/\CE{}}}
\L{\LB{\K{public}_\K{class}_\V{FloorLinker}_\{}}
\L{\LB{}\Tab{4}{\K{private}_\V{JFrame}_\V{window};}}
\L{\LB{}\Tab{4}{\K{private}_\V{MapComponent}_\V{imc};}}
\L{\LB{}\Tab{4}{\K{private}_\V{NodeItem}_\V{source},_\V{destination};}}
\L{\LB{}\Tab{4}{\K{private}_\V{String}_\V{srcMap},_\V{destMap};}}
\L{\LB{}\Tab{4}{}}
\index{FloorLinker}\Proc{FloorLinker}\L{\LB{}\Tab{4}{\K{public}_\V{FloorLinker}(\V{String}_\V{srcMap},_\V{String}_\V{destMap},_\V{NodeItem}_\V{source},_\V{Point}_\V{location})_\{}}
\L{\LB{}\Tab{8}{\K{this}.\V{source}_=_\V{source};}}
\L{\LB{}\Tab{8}{\K{this}.\V{destination}_=_\K{null};}}
\L{\LB{}\Tab{8}{\K{this}.\V{srcMap}_=_\V{srcMap};}}
\L{\LB{}\Tab{8}{\K{this}.\V{destMap}_=_\V{destMap};}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{window}_=_\K{new}_\V{JFrame}(\S{}\3Select_corresponding_node_on_\3\SE{}_+_\V{destMap});}}
\L{\LB{}\Tab{8}{\V{window}.\V{setDefaultCloseOperation}(\V{JFrame}.\V{DISPOSE\_ON\_CLOSE});}}
\L{\LB{}\Tab{8}{\V{window}.\V{setSize}(\N{500},_\N{350});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{imc}_=_\K{new}_\V{MapComponent}(\V{destMap});}}
\L{\LB{}\Tab{8}{\V{imc}.\V{nm}.\V{loadNodes}();}}
\L{\LB{}\Tab{8}{\V{imc}.\V{initMap}();}}
\L{\LB{}\Tab{8}{\V{imc}.\V{mm}.\V{centerAroundPoint}(\V{location});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{MouseMethods}_\V{mm}}\Tab{25}{=_\K{new}_\V{MouseMethods}();}}
\L{\LB{}\Tab{8}{\V{imc}.\V{addMouseListener}(\V{mm});}}
\L{\LB{}\Tab{8}{\V{imc}.\V{addMouseMotionListener}(\V{mm});}}
\L{\LB{}\Tab{8}{\V{imc}.\V{addMouseWheelListener}(\V{mm});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{Container}_\V{cp}_=_\V{window}.\V{getContentPane}();}}
\L{\LB{}\Tab{8}{\V{cp}.\V{setLayout}(\K{new}_\V{BorderLayout}());}}
\L{\LB{}\Tab{8}{\V{cp}.\V{add}(\V{imc});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{window}.\V{setVisible}(\K{true});}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}/**}}
\L{\LB{}\Tab{5}{*_Deletes_nodeId_in_destMap_from_having_a_floor_connection_to_srcMap.}}
\L{\LB{}\Tab{5}{*/\CE{}}}
\index{deleteConnection}\Proc{deleteConnection}\L{\LB{}\Tab{4}{\K{public}_\K{static}_\K{void}_\V{deleteConnection}(\V{String}_\V{srcMap},_\V{String}_\V{destMap},_\K{int}_\V{nodeId})_\{}}
\L{\LB{}\Tab{8}{\V{MapComponent}_\V{otherFloor}_=_\K{new}_\V{MapComponent}(\V{destMap});}}
\L{\LB{}\Tab{8}{\V{otherFloor}.\V{nm}.\V{loadNodes}();}}
\L{\LB{}\Tab{8}{\V{NodeItem}_\V{next}_=_\V{otherFloor}.\V{nm}.\V{getNodeById}(\V{nodeId});}}
\L{\LB{}\Tab{8}{\V{next}.\V{delFloorLink}(\V{srcMap});}}
\L{\LB{}\Tab{8}{\V{otherFloor}.\V{nm}.\V{saveNodes}();}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}/**}}
\L{\LB{}\Tab{5}{*_Listener_methods_for_mouse_actions_}}
\L{\LB{}\Tab{5}{*/\CE{}}}
\L{\LB{}\Tab{4}{\K{private}_\K{class}_\V{MouseMethods}_\K{extends}_\V{MouseInputAdapter}_\K{implements}_\V{MouseWheelListener}_\{}}
\L{\LB{}\Tab{8}{\K{private}_\V{Point}_\V{mouseClickPoint},_\V{mouseReleasePoint},_\V{newNode};}}
\L{\LB{}\Tab{8}{\K{private}_\K{boolean}_\V{mouseDragged},_\V{scrollDirection};}\Tab{68}{\C{}//_scroll_direction_=_false,_use_y,_true_use_x\CE{}}}
\index{mouseMoved}\Proc{mouseMoved}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mouseMoved}(\V{MouseEvent}_\V{e})_\{}}
\L{\LB{}\Tab{8}{\}}}
\index{mouseClicked}\Proc{mouseClicked}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mouseClicked}(\V{MouseEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\K{if}((\V{e}.\V{getButton}()==\N{1}_\|\,\|_\V{e}.\V{getButton}()==\N{3})_\&\&_\V{e}.\V{getClickCount}()==\N{2})_\{}}
\L{\LB{}\Tab{16}{\C{}//_Check_if_it_was_pressed_over_a_visible_node\CE{}}}
\L{\LB{}\Tab{16}{\C{}//_Loop_thru_nodes_and_verify_if_mouse_coords_are_within_boundaries_of_any_of_the_visible_sections.\CE{}}}
\L{\LB{}\Tab{16}{\C{}//System.out.println(\3Pressed_at:_\3_+_e.getPoint());\CE{}}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\C{}//_If_double-click_over_a_node,_edit_it\CE{}}}
\L{\LB{}\Tab{16}{\V{destination}_=_\V{imc}.\V{nm}.\V{getNodeAtCoords}(\V{e}.\V{getPoint}());}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\C{}//_Set_up_the_links_between_nodes\CE{}}}
\L{\LB{}\Tab{16}{\K{try}_\{}}
\L{\LB{}\Tab{20}{\V{destination}.\V{addFloorLink}(\V{srcMap},_\V{source});}}
\L{\LB{}\Tab{20}{\V{source}.\V{addFloorLink}(\V{destMap},_\V{destination});}}
\L{\LB{}\Tab{20}{\V{imc}.\V{nm}.\V{saveNodes}();}}
\L{\LB{}\Tab{16}{\}_\K{catch}_(\V{NullPointerException}_\V{err})_\{}}
\L{\LB{}\Tab{20}{\C{}//_No_node_double-clicked.\,.\,.\CE{}}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\V{window}.\V{dispose}();}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\index{mousePressed}\Proc{mousePressed}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mousePressed}(\V{MouseEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\K{this}.\V{mouseClickPoint}_=_\V{e}.\V{getPoint}();}}
\L{\LB{}\Tab{12}{\K{if}(\V{e}.\V{getButton}()==\N{2})}}
\L{\LB{}\Tab{16}{\K{this}.\V{scrollDirection}_=_!\K{this}.\V{scrollDirection};}}
\L{\LB{}\Tab{8}{\}}}
\index{mouseDragged}\Proc{mouseDragged}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mouseDragged}(\V{MouseEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\K{this}.\V{mouseDragged}_=_\K{true};}}
\L{\LB{}\Tab{8}{\}}}
\index{mouseReleased}\Proc{mouseReleased}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mouseReleased}(\V{MouseEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\K{this}.\V{mouseReleasePoint}_=_\V{e}.\V{getPoint}();}}
\L{\LB{}\Tab{12}{\K{if}(\K{this}.\V{mouseDragged}_\&\&_!\K{this}.\V{mouseReleasePoint}.\V{equals}(\K{this}.\V{mouseClickPoint}))_\{}}
\L{\LB{}\Tab{16}{\C{}//_If_dragged_over_node,_create_edge\CE{}}}
\L{\LB{}\Tab{16}{\C{}//_If_dragged_over_nothing,_move_node\CE{}}}
\L{\LB{}\Tab{16}{\K{if}(\V{e}.\V{getButton}()==\N{1}_\|\,\|_\V{e}.\V{getButton}()==\N{3})_\{}}
\L{\LB{}\Tab{20}{\V{NodeItem}_\V{selNode}_=_\V{imc}.\V{nm}.\V{getNodeAtCoords}(\K{this}.\V{mouseClickPoint});}}
\L{\LB{}\Tab{20}{\V{NodeItem}_\V{relNode}_=_\V{imc}.\V{nm}.\V{getNodeAtCoords}(\K{this}.\V{mouseReleasePoint});}}
\L{\LB{}\Tab{20}{\K{try}_\{}}
\L{\LB{}\Tab{24}{\K{if}(\V{relNode}!=\K{null}_\&\&_!\V{imc}.\V{nm}.\V{connected}(\V{selNode},_\V{relNode}))_\{}}
\L{\LB{}\Tab{28}{\V{EdgeItem}_\V{edge}_=_\K{new}_\V{EdgeItem}(\V{imc}.\V{map}(),_++\V{imc}.\V{edgeId});}}
\L{\LB{}\Tab{28}{\V{selNode}.\V{addEdge}(\V{edge});}}
\L{\LB{}\Tab{28}{\V{relNode}.\V{addEdge}(\V{edge});}}
\L{\LB{}\Tab{24}{\}}}
\L{\LB{}\Tab{24}{\K{else}_\C{}//_Move_node\CE{}}}
\L{\LB{}\Tab{28}{\V{selNode}.\V{setLocation}(\V{imc}.\V{mm}.\V{mouseCoordsToMapCoords}(\K{this}.\V{mouseReleasePoint}));}}
\L{\LB{}\Tab{24}{\V{imc}.\V{repaint}();}}
\L{\LB{}\Tab{20}{\}_\K{catch}_(\V{java}.\V{lang}.\V{NullPointerException}_\V{error})_\{}}
\L{\LB{}\Tab{24}{\C{}//_move_map_when_no_node_available\CE{}}}
\L{\LB{}\Tab{24}{\V{imc}.\V{mm}.\V{offsetByMouse}(\K{this}.\V{mouseClickPoint},_\K{this}.\V{mouseReleasePoint});}}
\L{\LB{}\Tab{24}{\C{}//sPanY.setValue((int)imc.getCoordinates().getY());\CE{}}}
\L{\LB{}\Tab{24}{\C{}//sPanX.setValue((int)imc.getCoordinates().getX());\CE{}}}
\L{\LB{}\Tab{20}{\}}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\K{this}.\V{mouseDragged}=\K{false};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\index{mouseWheelMoved}\Proc{mouseWheelMoved}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{mouseWheelMoved}(\V{MouseWheelEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\V{Point}_\V{newCoords}_=_\K{new}_\V{Point}();}}
\L{\LB{}\Tab{12}{\K{if}(\K{this}.\V{scrollDirection})_\{}}
\L{\LB{}\Tab{16}{\V{newCoords}.\V{setLocation}(_\V{imc}.\V{getCoordinates}().\V{getX}()\-(\V{e}.\V{getWheelRotation}()*\N{50}),_\V{imc}.\V{getCoordinates}().\V{getY}()_);}}
\L{\LB{}\Tab{16}{\C{}//sPanX.setValue((int)newCoords.getX());\CE{}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{else}_\{}}
\L{\LB{}\Tab{16}{\V{newCoords}.\V{setLocation}(_\V{imc}.\V{getCoordinates}().\V{getX}(),_\V{imc}.\V{getCoordinates}().\V{getY}()\-(\V{e}.\V{getWheelRotation}()*\N{50})_);}}
\L{\LB{}\Tab{16}{\C{}//sPanY.setValue((int)newCoords.getY());\CE{}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\V{imc}.\V{mm}.\V{setOrigin}(\V{newCoords});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{\}}}
